<?php

namespace App\Kuafu\Mqtt\Controller\Callback;

use App\Kuafu\Base\Controller\BaseController;
use App\Kuafu\Mqtt\Model\Log;
use Illuminate\Http\Request;

class MqttController extends BaseController
{
    public function messageAcked(Request $request)
    {
        $input = file_get_contents("php://input");
        if (empty($input)) {
            return;
        }

        $data = json_decode($input, true);
        if (!is_array($data) || empty($data['payload'])) {
            return;
        }
        $payload = json_decode($data['payload'], true);
        if (empty($payload['id'])) {
            return;
        }

        return Log::setStatus([$payload['id']], Log::STATUS_ACKED);
    }
}
